home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Utilities / GOCR / src / pgm2asc.h < prev    next >
C/C++ Source or Header  |  2000-05-23  |  6KB  |  153 lines

  1. #ifndef PGM2ASC_H
  2. #define PGM2ASC_H 1
  3.  
  4. #include "pnm.h"
  5.  
  6. #define Uint  unsigned int
  7. #define Uchar unsigned char
  8.  
  9. #define MAXlines 1024
  10.  
  11. struct tlines {
  12.     int num;
  13.     int dy;        /* offset for straight/skew lines dy(x+px) */
  14.     int m1[MAXlines],   /* start of line = upper bound of 'A' */
  15.         m2[MAXlines],   /* upper bound of 'e' */
  16.         m3[MAXlines],    /* lower bound of 'e' = baseline */
  17.         m4[MAXlines];    /* stop of line = lower bound of 'q' */
  18.     int x0[MAXlines],
  19.         x1[MAXlines];        /* left and right border */
  20.   };
  21. extern struct tlines lines;
  22.  
  23. // ---------------------------------------------------------------------
  24. // list of letter boxes (root+end or end==root)
  25. // ---------------------------------------------------------------------
  26. struct box {    // this structure should contain all pixel infos of a letter
  27.     int x0,x1,y0,y1,x,y,dots;    // xmin,xmax,ymin,ymax,reference-pixel,i-dots
  28.     struct box *next;    // points to next box
  29.     struct box *pre;    // points to predecessor (right word?)
  30.     char c;        // detected char '_' means unknown, '@' = picture
  31.     int num;        // same nummer = same char
  32.     int line;        // line number (points to struct tlines lines)
  33.     int m1,m2,m3,m4;    // m2 = upper boundary, m3 = baseline
  34.     // planed: sizeof hole_1, hole_2, certainty (run1=100%,run2=90%,etc.)
  35.     pix *p;        // pointer to pixmap (v0.2.5)
  36.  };
  37. extern struct box *box1,*box2;    // root, temp
  38.  
  39. struct environment {        // public for all
  40.     int cs;        // critical value (pixel<cs => black pixel)
  41.     int avX,avY;    // average X,Y
  42.     pix *p;        // pixelmap 8bit gray
  43. };
  44. extern struct environment env;
  45.  
  46. int in_str(char c, char *s);    /* return 0 or pos+1 */
  47. // ------------------------ end list-funcs --------------------------
  48. // test if pixel marked?
  49. int marked(pix &p, int  x, int  y);    // ret: 0=not_marked
  50.  
  51. // test if pixel --- later with error-correction
  52. int pixel(pix &p, int x, int y);    // ret: pixel-color (without marks)
  53.  
  54. void out_b(pix b, int x0, int y0, int dx, int dy, int cs );
  55. void out_x(box *px);
  56.  
  57. // ------------------------ feature extraction -----------------
  58. #define AT 7    // mark
  59. #define M1 1    // mark
  60. #define UP 1    // up        // look at loop, do not change!
  61. #define DO 2    // down    
  62. #define RI 3    // right
  63. #define LE 4    // left
  64. #define ST 7    // stop
  65. // -------------------------------------------------------------
  66. // detect maximas in of line overlapps (return in %) and line koord
  67. #define HOR 1    // horizontal
  68. #define VER 2    // vertikal
  69. #define RIS 3    // rising=steigend
  70. #define FAL 4    // falling=fallend
  71. struct tline { 
  72.    int x0,y0,x1,y1;     // middle points
  73.    };
  74. extern struct tline line;
  75.  
  76. // kalkulate the overlapp of the line (0-1) with black points 
  77. // by rekursiv bisection 
  78. // (evl. Fehlertoleranz mit pixel in Umgebung dx,dy suchen) (umschaltbar) ???
  79. // MidPoint Line Algorithm (Bresenham) Foley: ComputerGraphics better?
  80.  
  81. // gerade y=dy/dx*x+b, implizit d=F(x,y)=dy*x-dx*y+b*dx=0 
  82. // incrementell y(i+1)=m*(x(i)+1)+b, F(x+1,y+1)=f(F(x,y))
  83. int get_line(int x0, int y0, int x1, int y1, pix p, int cs, int ret);
  84. int get_line2(int x0, int y0, int x1, int y1, pix p, int cs, int ret);
  85.  
  86. // look for white 0x02 or black 0x01 dots (0x03 = white+black)
  87. char get_bw(int x0, int x1, int y0, int y1,
  88.              pix p, int cs,int mask);
  89.  
  90. // look for black crossing a line x0,y0,x1,y1
  91. // follow line and count crossings ([white]-black-transitions)
  92. int num_cross(int x0, int x1, int y0, int y1,
  93.                pix p,  int cs);
  94.  
  95. // -------------------------------------------------------------
  96. // mark edge-points
  97. //  - first move forward until b/w-edge
  98. //  - more than 2 pixel?
  99. //  - loop around
  100. //    - if forward    pixel : go up, rotate right
  101. //    - if forward no pixel : rotate left
  102. //  - stop if found first 2 pixel in same order
  103. // mit an rechter-Wand-entlang-gehen strategie
  104. // --------------------------------------------------------------
  105. // turmite game: inp: start-x,y, regel r_black=UP,r_white=RIght until border
  106. //               out: last-position
  107. // Zaehle dabei, Schritte,Sackgassen,xmax,ymax,ro-,ru-,lo-,lu-Ecken
  108. //
  109. // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  110. // SEHR GUTE IDEE VON MIR!!! KI-Methode!!! patentierbar?
  111. // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  112. //
  113. void turmite(pix &p, int &x, int &y, 
  114.              int x0, int x1, int y0, int y1, int cs, int rw, int rb);
  115.  
  116. // test if points are connected via t-pixel (rekursiv!)
  117. int joined(pix &p, int x0, int y0, int x1, int y1, int cs);
  118.  
  119. // move from x,y to direction r until pixel or l steps
  120. // return number of steps
  121. int loop(pix &p, int x, int y, int l, int cs, int col, int r);
  122.  
  123. // mark recursiv if no-pixel-neighbours=0 connected with (x,y)
  124. // better with neighbours of same color (more general) ???
  125. // (&~7)-pixmap, start-point, critical_value, mark
  126. // mark neighbouring pixel of same color, return number
  127. int mark_nn(pix &p, int  x, int  y, int &cs, int r);
  128.  
  129. void frame_nn(pix &p,  int  x,  int  y,
  130.               int &x0, int &x1, int &y0, int &y1,    // enlargeframe
  131.               int cs, int r);
  132.  
  133. // --- copy part of pix p into new pix b    ---- len=10000
  134. int copybox( pix p, int x0, int y0, int dx, int dy, pix *b, int len);
  135.  
  136. // look for white holes surrounded by black points
  137. // at moment white point with black in all for directions
  138. int num_hole(int x0, int x1, int y0, int y1, pix p, int cs);
  139.  
  140. // count for black nonconnected objects --- used for i,auml,ouml,etc.
  141. int num_obj(int x0, int x1, int y0, int y1, pix  p, int cs);
  142.  
  143. int distance(   pix p1, box *box1,    // box-frame
  144.         pix p2, box *box2, int cs);
  145.  
  146. // call the OCR engine ;)
  147. //char whatletter(box *box1,int cs);
  148.  
  149. // test if char c in string cset
  150. int strc(char c, char *cset);
  151.  
  152. #endif
  153.